

package com.hazelcast.transaction.impl.xa.operations;

import com.hazelcast.spi.impl.operationservice.Operation;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;

final class TransactionFinalizationCallback<V> implements BiConsumer<V, Throwable> {
    private final AtomicInteger counter = new AtomicInteger();
    private final int size;
    private final Operation operation;

    TransactionFinalizationCallback(Operation operation, int size) {
        this.operation = operation;
        this.size = size;
    }

    @Override
    public void accept(V v, Throwable throwable) {
        if (size == counter.incrementAndGet()) {
            operation.sendResponse(null);
        }
    }
}
